﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTP.AppFrame.PrototypeTools.Common;

namespace GTP.AppFrame.PrototypeTools.Business.Page
{
    /// <summary>
    /// 列表页
    /// </summary>
    public class GTPListPage : GTPPage
    {
        /// <summary>
        /// 生成页面
        /// <param name="property"></param>
        /// </summary>
        public override void Gennerator(BizProperty property)
        {
            string fileName = string.Empty;
            string data = string.Empty;
            //生成bizform
            fileName = string.Format("{0}ListPage.metadata.page", property.Name);
            data = GeneratorUtility.ReadConfigMetadata(GeneratorUtility.ConfigMetadataName.ListPage);
            data = property.Fill(data);
            data = data.Replace("{GTP-PT:PropertyList}", GetPropertyFieldList(property.MainEntityPropetyList));
            GeneratorUtility.WriteMetadata(fileName, data);
        }
        /// <summary>
        /// 生成GridView，用于子表
        /// </summary>
        /// <param name="propertyList"></param>
        /// <returns></returns>
        public string GenneratorGridColumn(List<EntityProperty> propertyList)
        {
            return GetPropertyFieldList(propertyList);
        }

        /// <summary>
        /// GridView的列
        /// <param name="propertyList"></param>
        /// </summary>
        /// <returns></returns>
        private string GetPropertyFieldList(List<EntityProperty> propertyList)
        {
            string result = string.Empty;
            //列不区分属性类型
            if (propertyList != null && propertyList.Count > 0)
            {
                string columnTemplate = GeneratorUtility.ReadConfigEntityField(EntityProperyType.Column);
                for (int i = 0; i < propertyList.Count; i++)
                {
                    result += columnTemplate.Replace("{GTP-PT:ID}", propertyList[i].ID.ToString()).Replace("{GTP-PT:Name}", propertyList[i].Name);
                }
            }
            return result;
        }
    }
}
